/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.targeter.rulesengine.model;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.model.BaseModel;
import com.liferay.portal.model.impl.BaseModelImpl;

import com.targeter.rulesengine.service.rulesLocalServiceUtil;

import java.io.Serializable;

import java.lang.reflect.Proxy;

import java.util.HashMap;
import java.util.Map;

/**
 * @author jsalaice
 */
public class rulesClp extends BaseModelImpl<rules> implements rules {
	public rulesClp() {
	}

	public Class<?> getModelClass() {
		return rules.class;
	}

	public String getModelClassName() {
		return rules.class.getName();
	}

	public long getPrimaryKey() {
		return _ruleId;
	}

	public void setPrimaryKey(long primaryKey) {
		setRuleId(primaryKey);
	}

	public Serializable getPrimaryKeyObj() {
		return new Long(_ruleId);
	}

	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	@Override
	public Map<String, Object> getModelAttributes() {
		Map<String, Object> attributes = new HashMap<String, Object>();

		attributes.put("ruleId", getRuleId());
		attributes.put("model", getModel());
		attributes.put("ruleName", getRuleName());
		attributes.put("active", getActive());
		attributes.put("drlFile", getDrlFile());

		return attributes;
	}

	@Override
	public void setModelAttributes(Map<String, Object> attributes) {
		Long ruleId = (Long)attributes.get("ruleId");

		if (ruleId != null) {
			setRuleId(ruleId);
		}

		String model = (String)attributes.get("model");

		if (model != null) {
			setModel(model);
		}

		String ruleName = (String)attributes.get("ruleName");

		if (ruleName != null) {
			setRuleName(ruleName);
		}

		Boolean active = (Boolean)attributes.get("active");

		if (active != null) {
			setActive(active);
		}

		String drlFile = (String)attributes.get("drlFile");

		if (drlFile != null) {
			setDrlFile(drlFile);
		}
	}

	public long getRuleId() {
		return _ruleId;
	}

	public void setRuleId(long ruleId) {
		_ruleId = ruleId;
	}

	public String getModel() {
		return _model;
	}

	public void setModel(String model) {
		_model = model;
	}

	public String getRuleName() {
		return _ruleName;
	}

	public void setRuleName(String ruleName) {
		_ruleName = ruleName;
	}

	public boolean getActive() {
		return _active;
	}

	public boolean isActive() {
		return _active;
	}

	public void setActive(boolean active) {
		_active = active;
	}

	public String getDrlFile() {
		return _drlFile;
	}

	public void setDrlFile(String drlFile) {
		_drlFile = drlFile;
	}

	public BaseModel<?> getrulesRemoteModel() {
		return _rulesRemoteModel;
	}

	public void setrulesRemoteModel(BaseModel<?> rulesRemoteModel) {
		_rulesRemoteModel = rulesRemoteModel;
	}

	public void persist() throws SystemException {
		if (this.isNew()) {
			rulesLocalServiceUtil.addrules(this);
		}
		else {
			rulesLocalServiceUtil.updaterules(this);
		}
	}

	@Override
	public rules toEscapedModel() {
		return (rules)Proxy.newProxyInstance(rules.class.getClassLoader(),
			new Class[] { rules.class }, new AutoEscapeBeanHandler(this));
	}

	@Override
	public Object clone() {
		rulesClp clone = new rulesClp();

		clone.setRuleId(getRuleId());
		clone.setModel(getModel());
		clone.setRuleName(getRuleName());
		clone.setActive(getActive());
		clone.setDrlFile(getDrlFile());

		return clone;
	}

	public int compareTo(rules rules) {
		int value = 0;

		if (getRuleId() < rules.getRuleId()) {
			value = -1;
		}
		else if (getRuleId() > rules.getRuleId()) {
			value = 1;
		}
		else {
			value = 0;
		}

		if (value != 0) {
			return value;
		}

		return 0;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}

		rulesClp rules = null;

		try {
			rules = (rulesClp)obj;
		}
		catch (ClassCastException cce) {
			return false;
		}

		long primaryKey = rules.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(11);

		sb.append("{ruleId=");
		sb.append(getRuleId());
		sb.append(", model=");
		sb.append(getModel());
		sb.append(", ruleName=");
		sb.append(getRuleName());
		sb.append(", active=");
		sb.append(getActive());
		sb.append(", drlFile=");
		sb.append(getDrlFile());
		sb.append("}");

		return sb.toString();
	}

	public String toXmlString() {
		StringBundler sb = new StringBundler(19);

		sb.append("<model><model-name>");
		sb.append("com.targeter.rulesengine.model.rules");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>ruleId</column-name><column-value><![CDATA[");
		sb.append(getRuleId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>model</column-name><column-value><![CDATA[");
		sb.append(getModel());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>ruleName</column-name><column-value><![CDATA[");
		sb.append(getRuleName());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>active</column-name><column-value><![CDATA[");
		sb.append(getActive());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>drlFile</column-name><column-value><![CDATA[");
		sb.append(getDrlFile());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private long _ruleId;
	private String _model;
	private String _ruleName;
	private boolean _active;
	private String _drlFile;
	private BaseModel<?> _rulesRemoteModel;
}